package com.lemon.common.config;

import com.lemon.common.web.interceptor.MvcInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 主要用于拦截器的配置
 *
 * @author ymh
 * @date 2019-04-05 14:32
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    /**
     * 拦截器配置
     *
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration interceptorRegistration = registry.addInterceptor(new MvcInterceptor());
        // 拦截路径
        interceptorRegistration.addPathPatterns("/**");

        // 不拦截的路径
        // 静态资源
        interceptorRegistration.excludePathPatterns("/static/**");
        interceptorRegistration.excludePathPatterns("/ueditor/**");
        interceptorRegistration.excludePathPatterns("/error");
        interceptorRegistration.excludePathPatterns("/upload/**");
        // 请求
        interceptorRegistration.excludePathPatterns("/user/login");
        interceptorRegistration.excludePathPatterns("/user/regist");
        interceptorRegistration.excludePathPatterns("/user/current");
        interceptorRegistration.excludePathPatterns("/user/check/**");
        interceptorRegistration.excludePathPatterns("/post/list");
        interceptorRegistration.excludePathPatterns("/upload");
        interceptorRegistration.excludePathPatterns("/imageUp");
        interceptorRegistration.excludePathPatterns("/post/*");
        interceptorRegistration.excludePathPatterns("/post/list/**");
    }
}
